import { Injectable } from '@angular/core';
import { Response } from '@angular/http';

@Injectable()
export class AppService {
    size: number;
    htmlDOM: any = document.getElementsByTagName('html')[0];
    setFont(): void {
        this.size = document.body.clientWidth / 320 * 10;
        if (this.size > 16) {
            this.size = 16;
        }
        if (this.size > 0) {
            this.htmlDOM.style.fontSize = this.size + 'px';
        } else {
            setTimeout(function () {
                this.setFont();
            }, 1000);
        }
    }
}

export class TransService {
    commons: any = {};
}

export const NetworkConfig: any = {
    domain: 'http://definesys.vicp.cc/',
    headers: {
        'DF_KEY': ''
    },
    paths: {
        'login': 'definesys/DFLoginService',  //登录-post
        'getTodo': 'definesys/DFBpmService/getExpTodoList',  //获取待办-post
        'getTodoDetail': 'definesys/DFBpmService/getExpTodoDetail', //获取待办明细-post
        'approve': 'definesys/DFBpmService/approveExpTodo', //同意审批-post
        'reject': 'definesys/DFBpmService/rejectExpTodo' //拒绝审批-post
    }
}

export const TaskConfig: any = {
    page1: {
        type: 'object',
        content: [
            {
                key: 'title',
                value: '申请内容'
            },
            {
                key: 'project_name',
                value: '项目名称'
            },
            {
                key: 'create_time',
                value: '创建时间'
            },
            {
                key: 'creator_name',
                value: '创建人'
            },
            {
                key: 'assignee_name',
                value: '处理人'
            },
            {
                key: 'total_amount',
                value: '总金额'
            },
            {
                key: 'status_meaning',
                value: '状态'
            }
        ]
    },
    page2: {
        type: 'array',
        content: [

            {
                key: 'station',
                value: '地点'
            },
            {
                key: 'exp_category',
                value: '报销类型'
            },
            {
                key: 'exp_type',
                value: '费用类型'
            },
            {
                key: 'exp_description',
                value: '费用描述'
            },
            {
                key: 'unit_price',
                value: '单价'
            },
            {
                key: 'exp_count',
                value: '数量'
            },
            {
                key: 'total',
                value: '总价'
            },
            {
                key: 'exp_start_date',
                value: '开始时间'
            },
            {
                key: 'exp_end_date',
                value: '结束时间'
            }
        ]
    }
}

export declare class LoginResponse extends Response {
    code: string;
    data: {
        token: string,
        userId: string
    };
    userMsg: string;
}

export declare class TasksResponse extends Response {
    code: string;
    data: {
        list: [
            {
                task_id: number,        //13264
                doc_num: string,        //IR00001004
                title: string,          //三菱项目宿舍安装电信宽带,
                project_name: string,   //上海三菱电梯-企管部项目（老项目）,
                create_time: string,    //2016-11-15 22:30:25,
                creator: string,        //004,
                creator_name: string,   //郑剑峰,
                approval_node: string,  //申请人确认收款,
                assignee: string,       //004,
                assignee_name: string,  //郑剑峰,
                total_amount: number,   //1600,
                status_meaning: string, //已付款,
                approve_date: string,   //2016-11-16 00:00:00
            }
        ],
        total: number
    };
    devMsg: string;
    userMsg: string;
}

export class TaskDetailResponse extends Response {
    code: string;
    data: {
        doc_number: string, //IR00000059,
        title: string, //出差补贴,
        project_name: string, // 百度外包项目,
        create_time: string, //2014-12-09 18:43:06,
        creator: string, //019,
        creator_name: string, // 程书泽,
        assignee: string, //019,
        assignee_name: string, //程书泽,
        total_amount: number, //1600,
        status_meaning: string, // 已付款,
        lines: [
            {
                line_id: number, //421,
                station: string, //北京,
                exp_category: string, // 项目实施,
                exp_type: string, //出差补贴,
                exp_description: string, //工作日的出差补贴（不含加班）,
                unit_price: number, //80,
                exp_count: number, //20,
                total: number, //80*20,
                exp_start_date: string, //2014-11-02 00:00:00,
                exp_end_date: string, //2014-11-30 00:00:00
            }
        ],
        total: number
    };
}

export class ApproveTaskResponse extends Response {
    
}